package com.lbj.core.ext

import java.io.*
import java.lang.Exception

/**
 * 作者：李炳军
 * 创建日期：2021-03-30  14:25
 * 释义：
 */
// 深拷贝
fun <T> MutableList<T>.deepCopyTest(): MutableList<T> {
    val srcList = arrayListOf<T>()
    var byteOut: ByteArrayOutputStream? = null
    var objOut: ObjectOutputStream? = null
    var byteIn: ByteArrayInputStream? = null
    var objIn: ObjectInputStream? = null
    try {
        byteOut = ByteArrayOutputStream()
        objOut = ObjectOutputStream(byteOut)
        objOut.writeObject(srcList)

        byteIn = ByteArrayInputStream(byteOut.toByteArray())
        objIn = ObjectInputStream(byteIn)
        return objIn.readObject() as MutableList<T>
    } catch (e: Exception) {

    } finally {
        byteOut?.close()
        objOut?.close()
        byteIn?.close()
        objIn?.close()
    }
    return ArrayList()
}